package org.linlinjava.litemall.admin.web;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallDistributionRule;
import org.linlinjava.litemall.db.service.LitemallDistributionRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author Administrator
 * @Date 2021/01/14
 */
@RestController
@RequestMapping("/admin/distribution")
public class AdminDistributionController {
    @Autowired
    private LitemallDistributionRuleService distributionRuleService;

    /**
     * 创建分销规则
     * @param distributionRule
     * @return
     */
    @PostMapping("/create")
    public Object create(@RequestBody LitemallDistributionRule distributionRule) {
        distributionRuleService.add(distributionRule);
        return ResponseUtil.ok();
    }

    /**
     * 修改分销规则
     * @param distributionRule
     * @return
     */
    @PostMapping("/update")
    public Object update(@RequestBody LitemallDistributionRule distributionRule) {
        distributionRuleService.update(distributionRule);
        return ResponseUtil.ok();
    }

    /**
     * 保存分销规则
     * @param distributionRule
     * @return
     */
    @PostMapping("/save")
    public Object save(@RequestBody LitemallDistributionRule distributionRule) {
        return ResponseUtil.ok(distributionRuleService.save(distributionRule));

    }

    /**
     * 删除分销规则
     * @param distributionId
     * @return
     */
    @PostMapping("/delete")
    public Object delete(@RequestBody Integer distributionId) {
        distributionRuleService.delete(distributionId);
        return ResponseUtil.ok();
    }

    /**
     * 展示所有分销规则
     * @return
     */
    @GetMapping("/list")
    public Object queryList(@RequestParam Integer type,@RequestParam Integer memberRuleId) {
        return ResponseUtil.ok(distributionRuleService.list(type, memberRuleId));
    }

    /**
     * 获取一个详情
     * @param distributionId
     * @return
     */
    @GetMapping("/findOne")
    public Object findOne(@RequestParam Integer distributionId){
        return ResponseUtil.ok(distributionRuleService.findById(distributionId));
    }


}
